clear all

********************************************************************************
********************************************************************************
**** When Can We Trust Regression Discontinuity Design Estimates from Close ****
*************** Elections? Evidence from Experimental Benchmarks ***************
********************************************************************************
********************************************************************************

* This file produces Table 1 in the main text of De Magalhaes et al. (Political
* Analysis).

cd "$dir"
use "$dir/data/personal_incumbency_advantage.dta", clear

la var elected "Lottery"

********************************************************************************

est clear

eststo: reg runningnextelection elected if rv==0 & country=="Colombia", cluster(constituency)
estadd local N_obs = e(N)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

eststo: reg runningnextelection elected if rv==0 & country=="Finland", cluster(constituency)
estadd local N_obs = e(N)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

esttab est* using "$dir/tables/table_1.tex", booktabs ///
keep(elected Conventional Robust) nomtitles ///
mgroups("Colombia" "Finland", pattern(1 0 0 0 0 1 0 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
replace  nonotes ///
ci(%9.3f) b(%9.3f) stats(N_obs h_l, fmt(0 2)  layout(@) ///
labels("\textit{N}" "Bandwidth")) collabels(none) ///
label nostar	eqlabels(none) ///
prehead(\begin{tabular}{l*{11}{c}} \toprule) ///
postfoot("") refcat(elected "\textbf{Panel A:} Running t+1", nolabel)

est clear

eststo: reg electednextelection elected if rv==0 & country=="Colombia", cluster(constituency)
estadd local N_obs = e(N)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

eststo: reg electednextelection elected if rv==0 & country=="Finland", cluster(constituency)
estadd local N_obs = e(N)
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust electednextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw =  e(h_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

esttab est* using "$dir/tables/table_1.tex", booktabs ///
keep(elected Conventional Robust) nomtitles nonumbers ///
append  nonotes ///
ci(%9.3f) b(%9.3f) stats(N_obs h_l bandwidth polynomial, fmt(0 2)  layout(@) ///
labels("\textit{N}" "Bandwidth" "Bandwidth selector" "Polynomial")) collabels(none) ///
label nostar	eqlabels(none) ///
prehead("") ///
postfoot(\bottomrule \end{tabular})	refcat(elected "\textbf{Panel B:} Elected t+1", nolabel)

est clear
